package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.OrderAttachment;
import com.ruoyi.system.service.IOrderAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单附件Controller
 *
 * @author hjf
 * @date 2025-06-23
 */
@RestController
@RequestMapping("/hmk/attachment")
public class OrderAttachmentController extends BaseController {
    @Autowired
    private IOrderAttachmentService orderAttachmentService;

    /**
     * 查询订单附件列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:attachment:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderAttachment orderAttachment) {
        startPage();
        List<OrderAttachment> list = orderAttachmentService.selectOrderAttachmentList(orderAttachment);
        return getDataTable(list);
    }

    /**
     * 导出订单附件列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:attachment:export')")
    //@Log(title = "订单附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderAttachment orderAttachment) {
        List<OrderAttachment> list = orderAttachmentService.selectOrderAttachmentList(orderAttachment);
        ExcelUtil<OrderAttachment> util = new ExcelUtil<OrderAttachment>(OrderAttachment.class);
        util.exportExcel(response, list, "订单附件数据");
    }

    /**
     * 获取订单附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('hmk:attachment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(orderAttachmentService.selectOrderAttachmentById(id));
    }

    /**
     * 新增订单附件
     */
    @PreAuthorize("@ss.hasPermi('hmk:attachment:add')")
    //@Log(title = "订单附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderAttachment orderAttachment) {
        return toAjax(orderAttachmentService.insertOrderAttachment(orderAttachment));
    }

    /**
     * 修改订单附件
     */
    @PreAuthorize("@ss.hasPermi('hmk:attachment:edit')")
    //@Log(title = "订单附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderAttachment orderAttachment) {
        return toAjax(orderAttachmentService.updateOrderAttachment(orderAttachment));
    }

    /**
     * 删除订单附件
     */
    @PreAuthorize("@ss.hasPermi('hmk:attachment:remove')")
    //@Log(title = "订单附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(orderAttachmentService.deleteOrderAttachmentByIds(ids));
    }
}
